<template>
  <div class="header">
    <img
      @click="gotoInfo"
      v-lazy="props.userInfo?.avatarUrl"
      class="info-nav-img"
      alt=""
    />
    <div class="info-name">{{ props.userInfo?.username }}</div>
    <ul class="info-detail" @click="gotoInfo">
      <li>
        <h1 class="content">{{ props.userInfo?.article }}</h1>
        <span>文章</span>
      </li>
      <li>
        <h1 class="content">{{ props.userInfo?.tag!.length }}</h1>
        <span>标签</span>
      </li>
      <li>
        <h1 class="content">{{ props.userInfo?.articleType }}</h1>
        <span>分类</span>
      </li>
    </ul>
    <div class="left-content">
      邮箱: {{ props.userInfo?.email ?? "还没有绑定邮箱" }}
    </div>
    <div class="left-content">
      性别:
      {{ props.userInfo?.gender ?? "null" }}
    </div>
  </div>
  <UserShareCard></UserShareCard>
  <div class="info-nav-tags" v-show="props.userInfo?.tag?.length">
    <div class="title">Tag</div>
    <template v-for="item in props.userInfo?.tag">
      <i
        @click="tagClick(item)"
        :title="item"
        :style="{ color: randomRgbColor() }"
        >{{ item }}</i
      >
    </template>
  </div>
  <slot name="tgas"></slot>
</template>

<script setup lang="ts">
import { useRoute } from "vue-router";
import { IuserInfo } from "@/store";
import router from "@/router";
import UserShareCard from "@/components/UserShareCard/UserShareCard.vue";

const props = defineProps<{
  userInfo?: Partial<IuserInfo>;
  uid?: number;
}>();
const route = useRoute();
const tagClick = async (tag: string) => {
  router.push({
    path: "/tag",
    query: {
      tag
    }
  });
};
const randomRgbColor = function () {
  const r = Math.floor(Math.random() * 255); //随机生成256以内r值
  const g = Math.floor(Math.random() * 255); //随机生成256以内g值
  const b = Math.floor(Math.random() * 255); //随机生成256以内b值
  return `rgb(${r},${g},${b})`; //返回rgb(r,g,b)格式颜色
};
const gotoInfo = () => {
  if (route.params.id) {
    router.push("/info/" + props.uid);
  } else {
    router.push("/info");
  }
};
</script>

<style scoped lang="less">
.header {
  background-color: #fff;
  width: 100%;
  text-align: center;
  padding: 10px;
  border-radius: 5px;
  box-shadow: 0 0 5px rgb(0 0 0 / 40%);
}
.info-nav-img {
  width: 80px;
  height: 5rem !important;
  margin: 10px 0 0;
  border-radius: 50%;
}
.info-name {
  margin: 10px 0;
  font-size: 1rem;
}
.content {
  font-weight: 500;
  font-size: 25px;
}
.left-content {
  text-align: left;
  padding-left: 10px;
  font-size: 14px;
  margin: 5px 0;
}
.info-detail {
  padding-top: 10px;
  border-top: 1px solid #ccc;
  width: 100%;
  display: flex;
  justify-content: space-around;
  text-align: center;
  margin: 0 0 10px;
  li {
    cursor: pointer;
    user-select: none;
    &:hover {
      color: #1e80ff;
    }
  }
}
.user-card-container {
  background-color: #fff;
  box-shadow: 0 0 5px rgb(0 0 0 / 40%);
  padding: 10px 5px;
  border-radius: 5px;
}
.info-nav-tags {
  background-color: #fff;
  box-shadow: 0 0 5px rgb(0 0 0 / 40%);
  padding: 10px;
  border-radius: 5px;
  margin-top: 10px;
  text-align: left;
  i {
    display: inline-block;
    margin-right: 10px;
    border-bottom: 1px solid transparent;
    font-size: 16px;
    transition: all 0.3s linear;
    &:hover {
      color: #1e80ff !important;
      cursor: pointer;
      transform: scale(1.2);
      border-bottom: 1px solid #1e80ff;
    }
  }
}
</style>
